/// <reference types = "../bin/RayTracing" />

namespace Demo {
    export class DemoSimple01 implements IDemo {
        Init(app: RAYTRACING.Application) {
            console.log("DemoSimple01");

            let scene = app.scene;
            let camera = scene.camera;

            //设置场景
            //地面、方块、球体、圆柱体
            //墙面
            let pFront = Tools.MakeModel(RAYTRACING.DefMeshType.Quad, new RAYTRACING.Color(0.8, 0.8, 0.8, 1), new RAYTRACING.Vector3(0, 1.5, 1.5), new RAYTRACING.Vector3(0, 0, 0), 3);
            let pBottom = Tools.MakeModel(RAYTRACING.DefMeshType.Quad, new RAYTRACING.Color(0.8, 0.8, 0.8, 1), new RAYTRACING.Vector3(0, 0, 0), new RAYTRACING.Vector3(90, 0, 0), 3);
            // let pBottom = Tools.MakeModel(RAYTRACING.DefMeshType.Quad, new RAYTRACING.Color(0.8, 0.8, 1, 1), new RAYTRACING.Vector3(0, 0, 0), new RAYTRACING.Vector3(90, 0, 0), 3);
            // pBottom.material.type = RAYTRACING.MaterialType.Specular;
            let pTop = Tools.MakeModel(RAYTRACING.DefMeshType.Quad, new RAYTRACING.Color(0.8, 0.8, 0.8, 1), new RAYTRACING.Vector3(0, 3, 0), new RAYTRACING.Vector3(-90, 0, 0), 3);
            let pLeft = Tools.MakeModel(RAYTRACING.DefMeshType.Quad, new RAYTRACING.Color(0, 0.6, 0, 1), new RAYTRACING.Vector3(-1.5, 1.5, 0), new RAYTRACING.Vector3(0, -90, 0), 3);
            let pRight = Tools.MakeModel(RAYTRACING.DefMeshType.Quad, new RAYTRACING.Color(0.6, 0, 0, 1), new RAYTRACING.Vector3(1.5, 1.5, 0), new RAYTRACING.Vector3(0, 90, 0), 3);
            //球体
            let ball0 = Tools.MakeModel(RAYTRACING.DefMeshType.Sphere, new RAYTRACING.Color(1, 1, 1, 1), new RAYTRACING.Vector3(-0.87, 0.45, 1.1), new RAYTRACING.Vector3(), -1);
            let ball1 = Tools.MakeModel(RAYTRACING.DefMeshType.Sphere, new RAYTRACING.Color(0.6, 0.6, 0.8, 1), new RAYTRACING.Vector3(0.73, 0.73, 0.86), new RAYTRACING.Vector3(), -1.5);
            ball1.material.type = RAYTRACING.MaterialType.Specular;
            let ball2 = Tools.MakeModel(RAYTRACING.DefMeshType.Sphere, new RAYTRACING.Color(0.9, 0.6, 0.6, 1), new RAYTRACING.Vector3(0, 0.27, 0.1), new RAYTRACING.Vector3(), -0.6);
            let ball3 = Tools.MakeModel(RAYTRACING.DefMeshType.Sphere, new RAYTRACING.Color(0.8, 0.8, 0.5, 1), new RAYTRACING.Vector3(-0.56, 0.27, -0.98), new RAYTRACING.Vector3(), -0.4);
            //灯
            let light = Tools.MakeModel(RAYTRACING.DefMeshType.Sphere, new RAYTRACING.Color(1, 1, 1, 1), new RAYTRACING.Vector3(0, 3, 0.1), new RAYTRACING.Vector3(), -1);
            light.scale.y *= 0.2;
            light.material.type = RAYTRACING.MaterialType.Light;

            let light1 = Tools.MakeModel(RAYTRACING.DefMeshType.Quad, new RAYTRACING.Color(20, 20, 20, 20), new RAYTRACING.Vector3(0, 2.9, -0.5), new RAYTRACING.Vector3(-90, 0, 0));
            light1.material.type = RAYTRACING.MaterialType.Light;

            //add
            scene.addNode(pFront);
            scene.addNode(pBottom);
            scene.addNode(pTop);
            scene.addNode(pLeft);
            scene.addNode(pRight);

            // scene.addNode(ball0);
            // scene.addNode(ball1);
            // scene.addNode(ball2);
            // scene.addNode(ball3);

            // scene.addNode(light);
            scene.addNode(light1);

            //设置相机
            camera.node.position.set(0, 1.5, -4);
            camera.fov = 60;
            camera.asp = app.asp;
            camera.near = 0.5;

            //路径追踪 计算
            scene.drawPathTraceing(app.width, app.height, 50, () => {
                console.log("drawPathTraceing end!");
            });
        }
    }
}